package com.dingding.service.activity.universal;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.FacadeResult;
import com.dingding.common.core.beans.UserLogin;
import com.dingding.facde.activity.dto.commonactivity.ReqGetActivityIndex;
import com.dingding.facde.activity.dto.commonactivity.ReqGetInviteInfo;
import com.dingding.facde.activity.dto.commonactivity.ReqRegFromActivity;
import com.dingding.facde.activity.dto.commonactivity.ReqStartAnActivity;
import com.dingding.facde.activity.dto.commonactivity.ReqStartToRegIndex;
import com.dingding.facde.activity.dto.commonactivity.ResGetActivityIndex;
import com.dingding.facde.activity.dto.commonactivity.ResGetInviteInfo;
import com.dingding.facde.activity.dto.commonactivity.ResRegFromActivity;
import com.dingding.facde.activity.dto.commonactivity.ResStartAnActivity;
import com.dingding.facde.activity.dto.commonactivity.ResStartToRegIndex;
import com.dingding.facde.activity.service.ICommonActivityFacade;
import com.dingding.service.activity.universal.core.biz.ICommonActivityService;
import com.dingding.service.share.dao.IActivityShareDao;

/**
 * @Description:通用活动分享的接口
 * @author fengshuonan
 * @date 2016年9月20日 下午3:34:55
 * @version 叮叮搭车
 * @since 2.4
 */
@Component("commonActivityFacade")
public class CommonActivityFacadeImpl implements ICommonActivityFacade {

	@Resource(name = "commonActivityService")
	private ICommonActivityService commonActivityService;

	@Resource(name = "activityShareDao")
	private IActivityShareDao activityShareDao;

	/**
	 * @Description:获取活动首页的详细信息接口
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResGetActivityIndex> getActivityIndexInfo(ReqGetActivityIndex reqGetActivityIndex) {
		ResGetActivityIndex activityIndexInfo = this.commonActivityService.getActivityIndexInfo(reqGetActivityIndex);
		return FacadeResult.SUCCESS(activityIndexInfo);
	}

	/**
	 * @Description:发起活动
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResStartAnActivity> startAnActivity(ReqStartAnActivity reqStartAnActivity) {
		ResStartAnActivity object = this.commonActivityService.startAnActivity(reqStartAnActivity);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:是否发起过某个活动
	 * @param userId
	 *            用户id
	 * @param activityId
	 *            活动id
	 * @author fengshuonan
	 * @return Boolean true 发起过 false 没发起过
	 * @since 2.4
	 */
	@Override
	public FacadeResult<Boolean> isStartedAnActivity(String userId, String activityId) {
		Boolean object = this.commonActivityService.isStartedAnActivity(userId, activityId);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:获取已发起活动的用户的邀请详情
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResGetInviteInfo> getInviteInfo(ReqGetInviteInfo reqGetInviteInfo) {
		ResGetInviteInfo object = this.commonActivityService.getInviteInfo(reqGetInviteInfo);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:活动注册
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResRegFromActivity> regFromActivity(ReqRegFromActivity reqRegFromActivity) {
		ResRegFromActivity object = this.commonActivityService.regFromActivity(reqRegFromActivity);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:跳转到注册主页的逻辑
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResStartToRegIndex> startToRegIndex(ReqStartToRegIndex reqStartToRegIndex) {
		ResStartToRegIndex object = this.commonActivityService.startToRegIndex(reqStartToRegIndex);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:发送短信验证码
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<Boolean> sendPhoneMsg(String telephone) {
		boolean object = this.commonActivityService.sendPhoneMsg(telephone);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:openId是否存在于数据库中
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<Boolean> isOpenIdInDb(String openId) {
		boolean object = this.commonActivityService.isOpenIdInDb(openId);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description:获取用户登录信息通过openId
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<UserLogin> getUserLoginByOpenId(String openId) {
		UserLogin userLogin = this.activityShareDao.getUserLoginByOpenId(openId);
		return FacadeResult.SUCCESS(userLogin);
	}

	/**
	 * @Description:验证手机号验证码是否正确
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<Boolean> validateTeleCode(String telephone, String code) {
		Boolean userLogin = this.commonActivityService.validateTeleCode(telephone, code);
		return FacadeResult.SUCCESS(userLogin);
	}

	/**
	 * @Description:通过电话号获取用户登录信息
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<UserLogin> getUserLoginByTele(String telephone) {
		UserLogin userLogin = this.commonActivityService.getUserLoginByTele(telephone);
		return FacadeResult.SUCCESS(userLogin);
	}
	
	/**
	 * @Description:发放优惠券的活动注册
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResRegFromActivity> regFromCoupon(ReqRegFromActivity reqRegFromActivity) {
		ResRegFromActivity object = this.commonActivityService.regFromCoupon(reqRegFromActivity);
		return FacadeResult.SUCCESS(object);
	}

	/**
	 * @Description 领取优惠券
	 * @author fengshuonan
	 */
	@Override
	public FacadeResult<ResRegFromActivity> getCoupon(String userId, String shareKey) {
		ResRegFromActivity object = this.commonActivityService.getCoupon(userId,shareKey);
		return FacadeResult.SUCCESS(object);
	}
}
